﻿using System;
using System.Collections.Generic;
using System.Text;
using TM.Common.Extensions;

namespace TM.Data.ViewModels
{
    public partial class VmProjectTask
    {
        public Guid ProjectId { get; set; }
        public string ProjectKey { get; set; }
        public Guid ID { get; set; }
        public Guid? ParentID { get; set; }
        public string Name { get; set; }
        public string DescDetails { get; set; }
        public VmTaskStatus Status { get; set; }
        public List<VmResource> Resources { get; set; }
        public List<VmScope> Scopes { get; set; }
        public List<VmEvident> Evidents { get; set; }
        public string Methology { get; set; }
        public DateTime? StartDate { get; set; }
        public DateTime? EndDate { get; set; }

        //Computed fields
        public TimeSpan Duration
        {
            get
            {
                if (EndDate.HasValue && StartDate.HasValue)
                {
                    return EndDate.Value - StartDate.Value;
                }

                return new TimeSpan(0);
            }

            set
            {
                if (!StartDate.HasValue) StartDate = DateTime.Today.StartOfToday();

                EndDate = StartDate.Value.AddSeconds(value.TotalSeconds);
            }
        }
        public object Constraint { get; set; }
        public decimal PercentCompleted { get; set; }

    }
}
